createFile
Files Sandbox MaheP Mar10 Revised

Creating a Local File

Problem
=======

Given the name of a file and it's path, how to create a file.

Solution
========

Creating a file in awk is as simple as directing the output to the name of the 
file. In the example below, we direct the output of the a print command to a 
file:

  print "Hello World!" > "MyFile.txt"

In the example above, a new file is created called MyFile.txt and the first
line of the file contains the string 

  Hello World!

If the file already exists, it is overwritten. Every execution of an awk 
program containing ">" for creating a file will result in creting a new file 
and opening a file discriptor that will be open till the completion of the
the program. What this means is that, the first call to ">" will create a file
and every subsequent call withing the same execution of the program will add 
more lines to the file.

Now, in case if we do not need to create a new file, but rather append to an 
existing file, the ">" has to be changed to ">>". 

  print "Hello World!" >> "MyFile.txt"

By default, if we do not specify the path, the default path will be the 
directory where the awk program is run from. To specify a path use:

  print "Hello World!" > "/path/to/file/MyFile.txt"

Combining the concepts above, the function to create a file is:

 function createFile(string, path, filename)
 {
     print string > path"/"filename;
 }

Author
======

Mahesh Patel



